package com.pzsh.controller;

import com.alibaba.fastjson.JSONObject;
import com.pzsh.constant.ConstantInterface;
import com.pzsh.entity.*;
import com.pzsh.entity.vo.admin.AdminCensusVo;
import com.pzsh.entity.vo.admin.AdminGoodsVo;
import com.pzsh.entity.vo.admin.AdminGradeVo;
import com.pzsh.enums.ErrorCodeEnum;
import com.pzsh.exception.ApiException;
import com.pzsh.redis.IRedisService;
import com.pzsh.service.IAPPService;
import com.pzsh.service.IGoodsService;
import com.pzsh.service.IOrderService;
import com.pzsh.service.IUserService;
import com.pzsh.swagger.ApiJsonObject;
import com.pzsh.swagger.ApiJsonProperty;
import com.pzsh.util.Asserts;
import com.pzsh.util.PageResult;
import com.pzsh.util.StringUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Set;

import static com.pzsh.constant.StaticVal.FACK_ADD;
import static com.pzsh.constant.StaticVal.isWindows;

/**
 * @program: 接口【管理台】
 * @description: 会员
 * @author: bite
 * @create:
 **/
@Slf4j
@Api(value = "admin", tags = "管理台")
@RestController
@RequestMapping("/admin")
public class AdminController {

    @Autowired
    private IGoodsService goodsService;

    @Autowired
    private IUserService iUserService;

    @Autowired
    private IOrderService iOrderService;

    @Autowired
    private IAPPService iappService;

    @Autowired
    private IRedisService iRedisService;

    @RequestMapping(value = "/login", method = RequestMethod.POST)
    @ApiOperation(tags = "管理台", httpMethod = "POST", value = "[管理台]登录", response = List.class)
    public ResponseWrapper login(
            @ApiJsonObject(name = "loginParams", value = {
                    @ApiJsonProperty(key = "username", value = "用户名"),
                    @ApiJsonProperty(key = "password", value = "密码"),
            }) @RequestBody JSONObject jsonParam) {
        try {
            String admin = jsonParam.getString("username");
            String pass = jsonParam.getString("password");
//            Asserts.naturalNumber(pageSize, "页码");
//            Asserts.naturalNumber(rows, "行数");
            if ("admin".equals(admin) && "a123456b".equals(pass)){//管理员
                JSONObject jsonObject = new JSONObject();
                jsonObject.put("access_token","owuid83jgdcjs.f56u566r9s3cws5a3s2544v.e856s6egwq3csqa");
                return ResponseWrapper.succeed(jsonObject);
            }

            if ("cust".equals(admin) && "cust3210".equals(pass)){//客服人员
                JSONObject jsonObject = new JSONObject();
                jsonObject.put("access_token","iekid3ugmb73jmec00w2.8t2559g52e21h56926wc5m5u9.8sa5s2696ws");
                return ResponseWrapper.succeed(jsonObject);
            }
            throw new ApiException(ErrorCodeEnum.PARAM_200027);
        } catch (ApiException e) {
            log.error(String.format("[管理台]登录失败，参数:%s, 错误信息:%s", jsonParam.toJSONString(), e.getMessage()));
            return ResponseWrapper.failed(e.getCode(), e.getMessage());
        } catch (Exception e) {
            log.error(String.format("[管理台]登录失败"), e);
            return ResponseWrapper.failed(ErrorCodeEnum.FL500);
        }
    }

    @RequestMapping(value = "/getVcodeList", method = RequestMethod.GET)
    @ApiOperation(tags = "管理台", httpMethod = "GET", value = "[管理台]获取所有验证码", response = List.class)
    public ResponseWrapper getVcodeList() {
        try {
            Set<String> sets = iRedisService.keys(ConstantInterface.VERIFICATION_CODE_FOR_REGISTER);
            HashMap<String,Object> map = new HashMap<>();
            if (sets != null){
                for (String str : sets) {
                    map.put(str, iRedisService.getString(str));
                }
            }
            return ResponseWrapper.succeed(map);
        } catch (ApiException e) {
            log.error(String.format("[管理台]获取所有验证码失败，参数:%s, 错误信息:%s", "jsonParam.toJSONString()", e.getMessage()));
            return ResponseWrapper.failed(e.getCode(), e.getMessage());
        } catch (Exception e) {
            log.error(String.format("[管理台]获取所有验证码失败"), e);
            return ResponseWrapper.failed(ErrorCodeEnum.FL500);
        }
    }

    @RequestMapping(value = "/goods/findList", method = RequestMethod.POST)
    @ApiOperation(tags = "管理台", httpMethod = "POST", value = "[管理台]查询商品列表", response = List.class)
    public ResponseWrapper findList(
            @ApiJsonObject(name = "adminGoodsfindListParams", value = {
                    @ApiJsonProperty(key = "page", value = "页码"),
                    @ApiJsonProperty(key = "limit", value = "行数"),
            }) @RequestBody JSONObject jsonParam) {
        try {
            Integer pageSize = jsonParam.getInteger("page");
            Integer rows = jsonParam.getInteger("limit");
            Asserts.naturalNumber(pageSize, "页码");
            Asserts.naturalNumber(rows, "行数");

            List<AdminGoodsVo> list = goodsService.selectByRowBounds(pageSize, rows);
            int count = goodsService.getGoodsCount();
            return ResponseWrapper.succeed(count,list);
        } catch (ApiException e) {
            log.error(String.format("[管理台]查询商品列表失败，参数:%s, 错误信息:%s", jsonParam.toJSONString(), e.getMessage()));
            return ResponseWrapper.failed(e.getCode(), e.getMessage());
        } catch (Exception e) {
            log.error(String.format("[管理台]查询商品列表失败"), e);
            return ResponseWrapper.failed(ErrorCodeEnum.FL500);
        }
    }

    @RequestMapping(value = "/goods/add", method = RequestMethod.POST)
    @ApiOperation(tags = "管理台", httpMethod = "POST", value = "[管理台]商品添加", response = String.class)
    public ResponseWrapper goodsAdd(
            @ApiJsonObject(name = "adminGoodsAddParams", value = {
                    @ApiJsonProperty(key = "goodsId", value = "商品id"),
                    @ApiJsonProperty(key = "goodsName", value = "商品名称"),
                    @ApiJsonProperty(key = "price", value = "原价"),
                    @ApiJsonProperty(key = "disPrice", value = "优惠价"),
                    @ApiJsonProperty(key = "rewardPs", value = "奖励积分"),
                    @ApiJsonProperty(key = "returnDays", value = "返还天数"),
                    @ApiJsonProperty(key = "mainPicture", value = "主图"),
                    @ApiJsonProperty(key = "mainPicture1", value = "主图1"),
                    @ApiJsonProperty(key = "mainPicture2", value = "主图2"),
                    @ApiJsonProperty(key = "content", value = "图文详情")
            }) @RequestBody JSONObject jsonParam) {
        try {

            Double price = (Double.valueOf(jsonParam.getString("price")) * 100);
            Integer price0 = price.intValue();
            Asserts.naturalNumber(price0, "原价");

            Double disPrice = (Double.valueOf(jsonParam.getString("disPrice")) * 100);
            Integer disPrice0 = disPrice.intValue();
            Asserts.naturalNumber(disPrice0, "优惠价");

            Double rewardPs = (Double.valueOf(jsonParam.getString("rewardPs")) * 100);
            Integer rewardPs0 = rewardPs.intValue();
            Asserts.naturalNumber(rewardPs0, "奖励积分");

//            Integer goodsId = jsonParam.getInteger("goodsId");
            String goodsName = jsonParam.getString("goodsName");
//            Integer price = jsonParam.getInteger("price");
//            Integer disPrice = jsonParam.getInteger("disPrice");
//            Integer rewardPs = jsonParam.getInteger("rewardPs");
            Integer returnDays = jsonParam.getInteger("returnDays");
            String mainPicture = jsonParam.getString("mainPicture");
            String mainPicture1 = jsonParam.getString("mainPicture1");
            String mainPicture2 = jsonParam.getString("mainPicture2");
            String content = jsonParam.getString("content");

            Asserts.notBlank(goodsName, "商品名称");
//            Asserts.naturalNumb(goodsId, "商品id");
//            Asserts.naturalNumb(price, "原价");
//            Asserts.naturalNumb(disPrice, "优惠价");
//            Asserts.naturalNumb(rewardPs, "奖励积分");
            Asserts.naturalNumb(returnDays, "返还天数");
            Asserts.notBlank(mainPicture, "主图");
            Asserts.notBlank(mainPicture1, "轮播图1");
            Asserts.notBlank(mainPicture2, "轮播图2");
            Asserts.notBlank(content, "图文详情");

            goodsService.insertGoods(goodsName, price0, disPrice0, rewardPs0, returnDays, mainPicture, mainPicture1, mainPicture2,content);
            return ResponseWrapper.succeed();
        } catch (ApiException e) {
            log.error(String.format("[管理台]商品添加失败，参数:%s, 错误信息:%s", jsonParam.toJSONString(), e.getMessage()));
            return ResponseWrapper.failed(e.getCode(), e.getMessage());
        } catch (Exception e) {
            log.error(String.format("[管理台]商品添加失败"), e);
            return ResponseWrapper.failed(ErrorCodeEnum.FL500);
        }
    }

    @RequestMapping(value = "/goods/edit", method = RequestMethod.POST)
    @ApiOperation(tags = "管理台", httpMethod = "POST", value = "[管理台]商品编辑", response = String.class)
    public ResponseWrapper goodsEdit(
            @ApiJsonObject(name = "adminGoodsEditParams", value = {
                    @ApiJsonProperty(key = "goodsId", value = "商品id"),
                    @ApiJsonProperty(key = "goodsName", value = "商品名称"),
                    @ApiJsonProperty(key = "price", value = "原价"),
                    @ApiJsonProperty(key = "disPrice", value = "优惠价"),
                    @ApiJsonProperty(key = "rewardPs", value = "奖励积分"),
                    @ApiJsonProperty(key = "returnDays", value = "返还天数"),
                    @ApiJsonProperty(key = "mainPicture", value = "主图"),
                    @ApiJsonProperty(key = "mainPicture1", value = "主图1"),
                    @ApiJsonProperty(key = "mainPicture2", value = "主图2"),
                    @ApiJsonProperty(key = "content", value = "图文详情")
            }) @RequestBody JSONObject jsonParam) {
        try {
            Double price = (Double.valueOf(jsonParam.getString("price")) * 100);
            Integer price0 = price.intValue();
            Asserts.naturalNumber(price0, "原价");

            Double disPrice = (Double.valueOf(jsonParam.getString("disPrice")) * 100);
            Integer disPrice0 = disPrice.intValue();
            Asserts.naturalNumber(disPrice0, "优惠价");

            Double rewardPs = (Double.valueOf(jsonParam.getString("rewardPs")) * 100);
            Integer rewardPs0 = rewardPs.intValue();
            Asserts.naturalNumber(rewardPs0, "奖励积分");

            Integer goodsId = jsonParam.getInteger("goodsId");
            String goodsName = jsonParam.getString("goodsName");
//            Integer price = jsonParam.getInteger("price");
//            Integer disPrice = jsonParam.getInteger("disPrice");
//            Integer rewardPs = jsonParam.getInteger("rewardPs");
            Integer returnDays = jsonParam.getInteger("returnDays");
            String mainPicture = jsonParam.getString("mainPicture");
            String mainPicture1 = jsonParam.getString("mainPicture1");
            String mainPicture2 = jsonParam.getString("mainPicture2");
            String content = jsonParam.getString("content");

            Asserts.notBlank(goodsName, "商品名称");
            Asserts.naturalNumb(goodsId, "商品id");
//            Asserts.naturalNumb(price, "原价");
//            Asserts.naturalNumb(disPrice, "优惠价");
//            Asserts.naturalNumb(rewardPs, "奖励积分");
            Asserts.naturalNumb(returnDays, "返还天数");
            Asserts.notBlank(mainPicture, "主图");
            Asserts.notBlank(mainPicture1, "轮播图1");
            Asserts.notBlank(mainPicture2, "轮播图2");
            Asserts.notBlank(content, "图文详情");

            goodsService.updateGoods(goodsId, goodsName, price0, disPrice0, rewardPs0, returnDays, mainPicture,mainPicture1,mainPicture2, content);
            return ResponseWrapper.succeed();
        } catch (ApiException e) {
            log.error(String.format("[管理台]商品编辑失败，参数:%s, 错误信息:%s", jsonParam.toJSONString(), e.getMessage()));
            return ResponseWrapper.failed(e.getCode(), e.getMessage());
        } catch (Exception e) {
            log.error(String.format("[管理台]商品编辑失败"), e);
            return ResponseWrapper.failed(ErrorCodeEnum.FL500);
        }
    }

    @RequestMapping(value = "/goods/del", method = RequestMethod.POST)
    @ApiOperation(tags = "管理台", httpMethod = "POST", value = "[管理台]报单商品删除", response = String.class)
    public ResponseWrapper goodsDel(
            @ApiJsonObject(name = "adminGoodsDelParams", value = {
                    @ApiJsonProperty(key = "goodsId", value = "商品id")
            }) @RequestBody JSONObject jsonParam) {
        try {
            Integer goodsId = jsonParam.getInteger("goodsId");
            Asserts.naturalNumb(goodsId, "商品id");

            goodsService.delGoods(goodsId);
            return ResponseWrapper.succeed();
        } catch (ApiException e) {
            log.error(String.format("[管理台]报单商品删除失败，参数:%s, 错误信息:%s", jsonParam.toJSONString(), e.getMessage()));
            return ResponseWrapper.failed(e.getCode(), e.getMessage());
        } catch (Exception e) {
            log.error(String.format("[管理台]报单商品删除失败"), e);
            return ResponseWrapper.failed(ErrorCodeEnum.FL500);
        }
    }

    @RequestMapping(value = "/grade/findList", method = RequestMethod.POST)
    @ApiOperation(tags = "管理台", httpMethod = "POST", value = "[管理台]查询复消列表", response = List.class)
    public ResponseWrapper gradeFindList(
            @ApiJsonObject(name = "adminGradefindListParams", value = {
                    @ApiJsonProperty(key = "page", value = "页码"),
                    @ApiJsonProperty(key = "limit", value = "行数"),
            }) @RequestBody JSONObject jsonParam) {
        try {
            Integer pageSize = jsonParam.getInteger("page");
            Integer rows = jsonParam.getInteger("limit");
            Asserts.naturalNumber(pageSize, "页码");
            Asserts.naturalNumber(rows, "行数");
            int count = goodsService.getGrageCount();
            List<AdminGradeVo> list = goodsService.selectByRowBoundsOfGrade(pageSize, rows);
            return ResponseWrapper.succeed(count,list);
        } catch (ApiException e) {
            log.error(String.format("[管理台]查询复消商品列表失败，参数:%s, 错误信息:%s", jsonParam.toJSONString(), e.getMessage()));
            return ResponseWrapper.failed(e.getCode(), e.getMessage());
        } catch (Exception e) {
            log.error(String.format("[管理台]查询复消商品列表失败"), e);
            return ResponseWrapper.failed(ErrorCodeEnum.FL500);
        }
    }

    @RequestMapping(value = "/grade/add", method = RequestMethod.POST)
    @ApiOperation(tags = "管理台", httpMethod = "POST", value = "[管理台]复消商品添加", response = String.class)
    public ResponseWrapper gradeAdd(
            @ApiJsonObject(name = "adminGradeAddParams", value = {
                    @ApiJsonProperty(key = "gradeName", value = "复消商品名称"),
                    @ApiJsonProperty(key = "price", value = "原价"),
                    @ApiJsonProperty(key = "disPrice", value = "优惠价"),
                    @ApiJsonProperty(key = "givePs", value = "赠送积分"),
                    @ApiJsonProperty(key = "reConsumption", value = "复消额度"),
                    @ApiJsonProperty(key = "team", value = "团队人数"),
                    @ApiJsonProperty(key = "recommend", value = "直推人数"),
                    @ApiJsonProperty(key = "fromGrade", value = "星级条件"),
                    @ApiJsonProperty(key = "toGrade", value = "目标星级"),
                    @ApiJsonProperty(key = "mainPicture", value = "主图"),
                    @ApiJsonProperty(key = "mainPicture1", value = "主图1"),
                    @ApiJsonProperty(key = "mainPicture2", value = "主图2"),
                    @ApiJsonProperty(key = "content", value = "图文详情")
            }) @RequestBody JSONObject jsonParam) {
        try {

            Double price = (Double.valueOf(jsonParam.getString("price")) * 100);
            Integer price0 = price.intValue();
            Asserts.naturalNumber(price0, "原价");

            Double disPrice = (Double.valueOf(jsonParam.getString("disPrice")) * 100);
            Integer disPrice0 = disPrice.intValue();
            Asserts.naturalNumber(disPrice0, "优惠价");

            Double givePs = (Double.valueOf(jsonParam.getString("givePs")) * 100);
            Integer givePs0 = givePs.intValue();
            Asserts.naturalNumber(givePs0, "赠送积分");

            String gradeName = jsonParam.getString("gradeName");
//            Integer price = jsonParam.getInteger("price");
//            Integer disPrice = jsonParam.getInteger("disPrice");
//            Integer givePs = jsonParam.getInteger("givePs");
            Integer reConsumption = jsonParam.getInteger("reConsumption");
            Integer team = jsonParam.getInteger("team");
            Integer recommend = jsonParam.getInteger("recommend");
            Integer fromGrade = jsonParam.getInteger("fromGrade");
            Integer toGrade = jsonParam.getInteger("toGrade");
            String mainPicture = jsonParam.getString("mainPicture");
            String mainPicture1 = jsonParam.getString("mainPicture1");
            String mainPicture2 = jsonParam.getString("mainPicture2");
            String content = jsonParam.getString("content");

            Asserts.notBlank(gradeName, "复消商品名称");
//            Asserts.naturalNumb(price, "原价");
//            Asserts.naturalNumb(disPrice, "优惠价");
//            Asserts.naturalNumb(givePs, "赠送积分");
//            Asserts.naturalNumb(reConsumption, "复消");
            Asserts.naturalNumb(team, "团队");
            Asserts.naturalNumb(recommend, "直推");
            Asserts.naturalNumbFromGrade(fromGrade, "星级条件");
            Asserts.naturalNumb(toGrade, "目标星级");
            Asserts.notBlank(mainPicture, "主图");
            Asserts.notBlank(mainPicture1, "轮播图1");
            Asserts.notBlank(mainPicture2, "轮播图2");
            Asserts.notBlank(content, "图文详情");

            goodsService.insertGrade(gradeName, price0, disPrice0, givePs0, reConsumption,team,fromGrade,toGrade,recommend,mainPicture, mainPicture1, mainPicture2, content);
            return ResponseWrapper.succeed();
        } catch (ApiException e) {
            log.error(String.format("[管理台]复消商品添加失败，参数:%s, 错误信息:%s", jsonParam.toJSONString(), e.getMessage()));
            return ResponseWrapper.failed(e.getCode(), e.getMessage());
        } catch (Exception e) {
            log.error(String.format("[管理台]复消商品添加失败"), e);
            return ResponseWrapper.failed(ErrorCodeEnum.FL500);
        }
    }



    @RequestMapping(value = "/grade/edit", method = RequestMethod.POST)
    @ApiOperation(tags = "管理台", httpMethod = "POST", value = "[管理台]复消商品编辑", response = String.class)
    public ResponseWrapper gradeEdit(
            @ApiJsonObject(name = "adminGradeEditParams", value = {
                    @ApiJsonProperty(key = "gradeId", value = "复消商品id"),
                    @ApiJsonProperty(key = "gradeName", value = "复消商品名称"),
                    @ApiJsonProperty(key = "price", value = "原价"),
                    @ApiJsonProperty(key = "disPrice", value = "优惠价"),
                    @ApiJsonProperty(key = "givePs", value = "赠送积分"),
                    @ApiJsonProperty(key = "reConsumption", value = "复消额度"),
                    @ApiJsonProperty(key = "team", value = "团队人数"),
                    @ApiJsonProperty(key = "recommend", value = "直推人数"),
                    @ApiJsonProperty(key = "fromGrade", value = "星级条件"),
                    @ApiJsonProperty(key = "toGrade", value = "目标星级"),
                    @ApiJsonProperty(key = "mainPicture", value = "主图"),
                    @ApiJsonProperty(key = "mainPicture1", value = "主图1"),
                    @ApiJsonProperty(key = "mainPicture2", value = "主图2"),
                    @ApiJsonProperty(key = "content", value = "图文详情")
            }) @RequestBody JSONObject jsonParam) {
        try {


            Double price = (Double.valueOf(jsonParam.getString("price")) * 100);
            Integer price0 = price.intValue();
            Asserts.naturalNumber(price0, "原价");

            Double disPrice = (Double.valueOf(jsonParam.getString("disPrice")) * 100);
            Integer disPrice0 = disPrice.intValue();
            Asserts.naturalNumber(disPrice0, "优惠价");

            Double givePs = (Double.valueOf(jsonParam.getString("givePs")) * 100);
            Integer givePs0 = givePs.intValue();
            Asserts.naturalNumber(givePs0, "赠送积分");

            Integer gradeId = jsonParam.getInteger("gradeId");
            String gradeName = jsonParam.getString("gradeName");
//            Integer price = jsonParam.getInteger("price");
//            Integer disPrice = jsonParam.getInteger("disPrice");
//            Integer givePs = jsonParam.getInteger("givePs");
            Integer reConsumption = jsonParam.getInteger("reConsumption");
            Integer team = jsonParam.getInteger("team");
            Integer recommend = jsonParam.getInteger("recommend");
            Integer fromGrade = jsonParam.getInteger("fromGrade");
            Integer toGrade = jsonParam.getInteger("toGrade");
            String mainPicture = jsonParam.getString("mainPicture");
            String mainPicture1 = jsonParam.getString("mainPicture1");
            String mainPicture2 = jsonParam.getString("mainPicture2");
            String content = jsonParam.getString("content");

            Asserts.notBlank(gradeName, "复消商品名称");
            Asserts.naturalNumb(gradeId, "复消商品id");
//            Asserts.naturalNumb(price, "原价");
//            Asserts.naturalNumb(disPrice, "优惠价");
//            Asserts.naturalNumb(givePs, "赠送积分");
//            Asserts.naturalNumb(reConsumption, "复消");
            Asserts.naturalNumb(team, "团队");
            Asserts.naturalNumb(recommend, "直推");
            Asserts.naturalNumbFromGrade(fromGrade, "星级条件");
            Asserts.naturalNumb(toGrade, "目标星级");
            Asserts.notBlank(mainPicture, "主图");
            Asserts.notBlank(mainPicture1, "轮播图1");
            Asserts.notBlank(mainPicture2, "轮播图2");
            Asserts.notBlank(content, "图文详情");

            goodsService.updateGrade(gradeId, gradeName, price0, disPrice0, givePs0, reConsumption,team,fromGrade,toGrade,recommend,mainPicture, mainPicture1, mainPicture2, content);
            return ResponseWrapper.succeed();
        } catch (ApiException e) {
            log.error(String.format("[管理台]复消商品编辑失败，参数:%s, 错误信息:%s", jsonParam.toJSONString(), e.getMessage()));
            return ResponseWrapper.failed(e.getCode(), e.getMessage());
        } catch (Exception e) {
            log.error(String.format("[管理台]复消商品编辑失败"), e);
            return ResponseWrapper.failed(ErrorCodeEnum.FL500);
        }
    }

    @RequestMapping(value = "/grade/del", method = RequestMethod.POST)
    @ApiOperation(tags = "管理台", httpMethod = "POST", value = "[管理台]复消商品删除", response = String.class)
    public ResponseWrapper gradeDel(
            @ApiJsonObject(name = "adminGradeDelParams", value = {
                    @ApiJsonProperty(key = "gradeId", value = "商品id")
            }) @RequestBody JSONObject jsonParam) {
        try {
            Integer gradeId = jsonParam.getInteger("gradeId");
            Asserts.naturalNumb(gradeId, "商品id");

            goodsService.delGrade(gradeId);
            return ResponseWrapper.succeed();
        } catch (ApiException e) {
            log.error(String.format("[管理台]复消商品删除失败，参数:%s, 错误信息:%s", jsonParam.toJSONString(), e.getMessage()));
            return ResponseWrapper.failed(e.getCode(), e.getMessage());
        } catch (Exception e) {
            log.error(String.format("[管理台]复消商品删除失败"), e);
            return ResponseWrapper.failed(ErrorCodeEnum.FL500);
        }
    }

    @RequestMapping(value = "/userList", method = RequestMethod.POST)
    @ApiOperation(tags = "管理台", httpMethod = "POST", value = "[后台]获取用户列表", response = List.class)
    public ResponseWrapper userList(
            @ApiJsonObject(name = "userListParams", value = {
                    @ApiJsonProperty(key = "page", value = "页码"),
                    @ApiJsonProperty(key = "limit", value = "行数"),
                    @ApiJsonProperty(key = "account", value = "用户名"),
                    @ApiJsonProperty(key = "realName", value = "真实姓名"),
                    @ApiJsonProperty(key = "black", value = "拉黑"),
                    @ApiJsonProperty(key = "grade", value = "星级")
            }) @RequestBody JSONObject jsonParam) {
        try {
            Integer pageSize = jsonParam.getInteger("page");
            Integer rows = jsonParam.getInteger("limit");
            Asserts.naturalNumber(pageSize, "页码");
            Asserts.naturalNumber(rows, "行数");

            String account = jsonParam.getString("account");
            String realName = jsonParam.getString("realName");
            Integer black = jsonParam.getInteger("black");
            Integer grade = jsonParam.getInteger("grade");

            PageResult<List<UserEntity>> pageResult = iUserService.selectByRowBounds(account, realName, black, pageSize, rows, grade);
            int count = pageResult.getTotal();
            return ResponseWrapper.succeed(count,pageResult.getData());
        } catch (ApiException e) {
            log.error(String.format("[后台]获取用户列表失败，参数:%s, 错误信息:%s", jsonParam.toJSONString(), e.getMessage()));
            return ResponseWrapper.failed(e.getCode(), e.getMessage());
        } catch (Exception e) {
            log.error(String.format("[后台]获取用户列表失败"), e);
            return ResponseWrapper.failed(ErrorCodeEnum.FL500);
        }
    }
    @RequestMapping(value = "order/findList", method = RequestMethod.POST)
    @ApiOperation(tags = "管理台", httpMethod = "POST", value = "[后台]获取订单列表", response = List.class)
    public ResponseWrapper orderList(
            @ApiJsonObject(name = "orderListParams", value = {
                    @ApiJsonProperty(key = "page", value = "页码"),
                    @ApiJsonProperty(key = "limit", value = "行数"),
                    @ApiJsonProperty(key = "account", value = "用户名"),
                    @ApiJsonProperty(key = "status", value = "订单状态"),
                    @ApiJsonProperty(key = "gtype", value = "消费类型")
            }) @RequestBody JSONObject jsonParam) {
        try {
            Integer pageSize = jsonParam.getInteger("page");
            Integer rows = jsonParam.getInteger("limit");
            Asserts.naturalNumber(pageSize, "页码");
            Asserts.naturalNumber(rows, "行数");


            String account = jsonParam.getString("account");
            Integer status = jsonParam.getInteger("status");
            Integer gtype = jsonParam.getInteger("gtype");

            PageResult<List<OrderEntity>> pageResult = iOrderService.selectByRowBounds(account,status,gtype, pageSize,rows);
            int count = pageResult.getTotal();
            return ResponseWrapper.succeed(count,pageResult.getData());
        } catch (ApiException e) {
            log.error(String.format("[后台]获取订单列表失败，参数:%s, 错误信息:%s", jsonParam.toJSONString(), e.getMessage()));
            return ResponseWrapper.failed(e.getCode(), e.getMessage());
        } catch (Exception e) {
            log.error(String.format("[后台]获取订单列表失败"), e);
            return ResponseWrapper.failed(ErrorCodeEnum.FL500);
        }
    }

    @RequestMapping(value = "order/logistics", method = RequestMethod.POST)
    @ApiOperation(tags = "管理台", httpMethod = "POST", value = "[后台]订单发货", response = String.class)
    public ResponseWrapper orderLogistics(
            @ApiJsonObject(name = "orderLogisticsParams", value = {
                    @ApiJsonProperty(key = "orderId", value = "订单ID"),
                    @ApiJsonProperty(key = "commp", value = "物流公司"),
                    @ApiJsonProperty(key = "commpOrder", value = "物流订单号"),
            }) @RequestBody JSONObject jsonParam) {
        try {

            Integer orderId = jsonParam.getInteger("orderId");
            String commp = jsonParam.getString("commp");
            String commpOrder = jsonParam.getString("commpOrder");
            Asserts.notBlank(commpOrder, "物流订单号");
            Asserts.notBlank(commp, "物流公司");
            Asserts.naturalNumber(orderId, "订单ID");

            iOrderService.updateOrderLogistics(orderId, commp, commpOrder);
            return ResponseWrapper.succeed();

        } catch (ApiException e) {
            log.error(String.format("[后台]获取订单列表失败，参数:%s, 错误信息:%s", jsonParam.toJSONString(), e.getMessage()));
            return ResponseWrapper.failed(e.getCode(), e.getMessage());
        } catch (Exception e) {
            log.error(String.format("[后台]获取订单列表失败"), e);
            return ResponseWrapper.failed(ErrorCodeEnum.FL500);
        }
    }

    @RequestMapping(value = "/order/edit", method = RequestMethod.POST)
    @ApiOperation(tags = "管理台", httpMethod = "POST", value = "[管理台]订单编辑", response = String.class)
    public ResponseWrapper orderEdit(
            @ApiJsonObject(name = "adminOrderEditParams", value = {
                    @ApiJsonProperty(key = "orderId", value = "订单id"),
                    @ApiJsonProperty(key = "address", value = "收货地址"),
                    @ApiJsonProperty(key = "consignee", value = "收货人"),
                    @ApiJsonProperty(key = "consigneeMobile", value = "收货手机")
            }) @RequestBody JSONObject jsonParam) {
        try {

            Integer orderId = jsonParam.getInteger("orderId");
            String address = jsonParam.getString("address");
            String consignee = jsonParam.getString("consignee");
            String consigneeMobile = jsonParam.getString("consigneeMobile");

            Asserts.naturalNumb(orderId, "订单id");
            Asserts.notBlank(address, "收货地址");
            Asserts.notBlank(consignee, "收货人");
            Asserts.notBlank(consigneeMobile, "收货手机");

            goodsService.updateOrder(orderId, address, consignee, consigneeMobile);
            return ResponseWrapper.succeed();
        } catch (ApiException e) {
            log.error(String.format("[管理台]订单编辑失败，参数:%s, 错误信息:%s", jsonParam.toJSONString(), e.getMessage()));
            return ResponseWrapper.failed(e.getCode(), e.getMessage());
        } catch (Exception e) {
            log.error(String.format("[管理台]订单编辑失败"), e);
            return ResponseWrapper.failed(ErrorCodeEnum.FL500);
        }
    }

    @RequestMapping(value = "/order/cancel", method = RequestMethod.POST)
    @ApiOperation(tags = "管理台", httpMethod = "POST", value = "[管理台]订单取消", response = String.class)
    public ResponseWrapper orderCancel(
            @ApiJsonObject(name = "adminOrderCancelParams", value = {
                    @ApiJsonProperty(key = "orderId", value = "订单id")
            }) @RequestBody JSONObject jsonParam) {
        try {
            Integer orderId = jsonParam.getInteger("orderId");
            Asserts.naturalNumb(orderId, "订单id");

            goodsService.cancelOrder(orderId);
            return ResponseWrapper.succeed();
        } catch (ApiException e) {
            log.error(String.format("[管理台]订单取消失败，参数:%s, 错误信息:%s", jsonParam.toJSONString(), e.getMessage()));
            return ResponseWrapper.failed(e.getCode(), e.getMessage());
        } catch (Exception e) {
            log.error(String.format("[管理台]订单取消失败"), e);
            return ResponseWrapper.failed(ErrorCodeEnum.FL500);
        }

    }

    @RequestMapping(value = "tran/list", method = RequestMethod.POST)
    @ApiOperation(tags = "管理台", httpMethod = "POST", value = "[后台]获取交易记录", response = List.class)
    public ResponseWrapper tranList(
            @ApiJsonObject(name = "tranListParams", value = {
                    @ApiJsonProperty(key = "page", value = "页码"),
                    @ApiJsonProperty(key = "limit", value = "行数"),
            }) @RequestBody JSONObject jsonParam) {
        try {
            Integer pageSize = jsonParam.getInteger("page");
            Integer rows = jsonParam.getInteger("limit");
            Asserts.naturalNumber(pageSize, "页码");
            Asserts.naturalNumber(rows, "行数");

            PageResult<List<TransactionEntity>> list = iOrderService.getTranList(pageSize,rows);
            int count = list.getTotal();
            return ResponseWrapper.succeed(count,list.getData());
        } catch (ApiException e) {
            log.error(String.format("[后台]获取交易记录失败，参数:%s, 错误信息:%s", jsonParam.toJSONString(), e.getMessage()));
            return ResponseWrapper.failed(e.getCode(), e.getMessage());
        } catch (Exception e) {
            log.error(String.format("[后台]获取交易记录失败"), e);
            return ResponseWrapper.failed(ErrorCodeEnum.FL500);
        }
    }

    @RequestMapping(value = "tran/listBy", method = RequestMethod.POST)
    @ApiOperation(tags = "管理台", httpMethod = "POST", value = "[后台]获取交易记录", response = List.class)
    public ResponseWrapper tranListBy(
            @ApiJsonObject(name = "tranListByParams", value = {
                    @ApiJsonProperty(key = "page", value = "页码"),
                    @ApiJsonProperty(key = "limit", value = "行数"),
                    @ApiJsonProperty(key = "account", value = "用户名")
            }) @RequestBody JSONObject jsonParam) {
        try {
            Integer pageSize = jsonParam.getInteger("page");
            Integer rows = jsonParam.getInteger("limit");
            Asserts.naturalNumber(pageSize, "页码");
            Asserts.naturalNumber(rows, "行数");

            String account = jsonParam.getString("account");

            PageResult<List<TransactionEntity>> list = iOrderService.getTranListBy(pageSize,rows,account);
            int count = list.getTotal();
            return ResponseWrapper.succeed(count,list.getData());
        } catch (ApiException e) {
            log.error(String.format("[后台]获取交易记录失败，参数:%s, 错误信息:%s", jsonParam.toJSONString(), e.getMessage()));
            return ResponseWrapper.failed(e.getCode(), e.getMessage());
        } catch (Exception e) {
            log.error(String.format("[后台]获取交易记录失败"), e);
            return ResponseWrapper.failed(ErrorCodeEnum.FL500);
        }
    }

    @RequestMapping(value = "/takeBlack", method = RequestMethod.POST)
    @ApiOperation(tags = "管理台", httpMethod = "POST", value = "[后台]拉黑用户/拉白用户", response = List.class)
    public ResponseWrapper takeBlack(
            @ApiJsonObject(name = "takeBlackParams", value = {
                    @ApiJsonProperty(key = "userId", value = "用户id")
            }) @RequestBody JSONObject jsonParam) {
        try {
            Integer userId = jsonParam.getInteger("userId");
            Asserts.naturalNumber(userId, "用户id");

            iUserService.takeBlack(userId);
            return ResponseWrapper.succeed();
        } catch (ApiException e) {
            log.error(String.format("[后台]拉黑用户/拉白用户失败，参数:%s, 错误信息:%s", jsonParam.toJSONString(), e.getMessage()));
            return ResponseWrapper.failed(e.getCode(), e.getMessage());
        } catch (Exception e) {
            log.error(String.format("[后台]拉黑用户/拉白用户失败"), e);
            return ResponseWrapper.failed(ErrorCodeEnum.FL500);
        }
    }

    @RequestMapping(value = "/whiteUser", method = RequestMethod.POST)
    @ApiOperation(tags = "管理台", httpMethod = "POST", value = "[后台]用户白名单（不判断是否vip）", response = List.class)
    public ResponseWrapper whiteUser(
            @ApiJsonObject(name = "whiteUserParams", value = {
                    @ApiJsonProperty(key = "userId", value = "用户id")
            }) @RequestBody JSONObject jsonParam) {
        try {
            Integer userId = jsonParam.getInteger("userId");
            Asserts.naturalNumber(userId, "用户id");

            iUserService.whiteUser(userId);
            return ResponseWrapper.succeed();
        } catch (ApiException e) {
            log.error(String.format("[后台]用户白名单失败，参数:%s, 错误信息:%s", jsonParam.toJSONString(), e.getMessage()));
            return ResponseWrapper.failed(e.getCode(), e.getMessage());
        } catch (Exception e) {
            log.error(String.format("[后台]用户白名单失败"), e);
            return ResponseWrapper.failed(ErrorCodeEnum.FL500);
        }
    }


    @RequestMapping(value = "/getPzsh", method = RequestMethod.POST)
    @ApiOperation(tags = "管理台", httpMethod = "POST", value = "[后台]获取PZSH市值", response = List.class)
    public ResponseWrapper getPzsh(
            @ApiJsonObject(name = "getPzshParams", value = {}) @RequestBody JSONObject jsonParam) {
        try {

            String pzsh = iUserService.getPzsh();
            return ResponseWrapper.succeed(pzsh);
        } catch (ApiException e) {
            log.error(String.format("[后台]获取PZSH市值失败，参数:%s, 错误信息:%s", jsonParam.toJSONString(), e.getMessage()));
            return ResponseWrapper.failed(e.getCode(), e.getMessage());
        } catch (Exception e) {
            log.error(String.format("[后台]获取PZSH市值失败"), e);
            return ResponseWrapper.failed(ErrorCodeEnum.FL500);
        }
    }
    @RequestMapping(value = "/setPzsh", method = RequestMethod.POST)
    @ApiOperation(tags = "管理台", httpMethod = "POST", value = "[后台]设置PZSH市值", response = String.class)
    public ResponseWrapper setPzsh(
            @ApiJsonObject(name = "setPzshParams", value = {
                    @ApiJsonProperty(key = "pzsh", value = "pzsh 市值")
            }) @RequestBody JSONObject jsonParam) {
        try {
            Double pzsh = (Double.valueOf(jsonParam.getString("pzsh")) * 100);
            Integer iii = pzsh.intValue();
            Asserts.naturalNumber(iii, "pzsh 市值");

            iUserService.setPzsh(iii);
            return ResponseWrapper.succeed();
        } catch (ApiException e) {
            log.error(String.format("[后台]设置PZSH市值失败，参数:%s, 错误信息:%s", jsonParam.toJSONString(), e.getMessage()));
            return ResponseWrapper.failed(e.getCode(), e.getMessage());
        } catch (Exception e) {
            log.error(String.format("[后台]设置PZSH市值失败"), e);
            return ResponseWrapper.failed(ErrorCodeEnum.FL500);
        }
    }

    @RequestMapping(value = "/getLevelRule", method = RequestMethod.POST)
    @ApiOperation(tags = "管理台", httpMethod = "POST", value = "[后台]获取升级规则", response = String.class)
    public ResponseWrapper getLevelRule(
            @ApiJsonObject(name = "getLevelRuleParams", value = {}) @RequestBody JSONObject jsonParam) {
        try {
            String levelRule = iUserService.getLevelRule();
            return ResponseWrapper.succeed(levelRule);
        } catch (ApiException e) {
            log.error(String.format("[后台]获取升级规则失败，参数:%s, 错误信息:%s", jsonParam.toJSONString(), e.getMessage()));
            return ResponseWrapper.failed(e.getCode(), e.getMessage());
        } catch (Exception e) {
            log.error(String.format("[后台]获取升级规则失败"), e);
            return ResponseWrapper.failed(ErrorCodeEnum.FL500);
        }
    }

    @RequestMapping(value = "/setLevelRule", method = RequestMethod.POST)
    @ApiOperation(tags = "管理台", httpMethod = "POST", value = "[后台]设置升级规则", response = String.class)
    public ResponseWrapper setLevelRule(
            @ApiJsonObject(name = "setLevelRuleParams", value = {
                    @ApiJsonProperty(key = "levelRule", value = "升级规则")
            }) @RequestBody JSONObject jsonParam) {
        try {
            String levelRule = jsonParam.getString("levelRule");
            Asserts.notBlank(levelRule, "升级规则");

            iUserService.setLevelRule(levelRule);
            return ResponseWrapper.succeed();
        } catch (ApiException e) {
            log.error(String.format("[后台]设置升级规则失败，参数:%s, 错误信息:%s", jsonParam.toJSONString(), e.getMessage()));
            return ResponseWrapper.failed(e.getCode(), e.getMessage());
        } catch (Exception e) {
            log.error(String.format("[后台]设置升级规则失败"), e);
            return ResponseWrapper.failed(ErrorCodeEnum.FL500);
        }
    }

    @RequestMapping(value = "/getMiner", method = RequestMethod.POST)
    @ApiOperation(tags = "管理台", httpMethod = "POST", value = "[后台]获取矿工费", response = String.class)
    public ResponseWrapper getMiner(
            @ApiJsonObject(name = "getMinerParams", value = {}) @RequestBody JSONObject jsonParam) {
        try {
            String miner = iUserService.getMiner();
            return ResponseWrapper.succeed(miner);
        } catch (ApiException e) {
            log.error(String.format("[后台]获取矿工费失败，参数:%s, 错误信息:%s", jsonParam.toJSONString(), e.getMessage()));
            return ResponseWrapper.failed(e.getCode(), e.getMessage());
        } catch (Exception e) {
            log.error(String.format("[后台]获取矿工费失败"), e);
            return ResponseWrapper.failed(ErrorCodeEnum.FL500);
        }
    }
    @RequestMapping(value = "/setMiner", method = RequestMethod.POST)
    @ApiOperation(tags = "管理台", httpMethod = "POST", value = "[后台]设置矿工费", response = List.class)
    public ResponseWrapper setMiner(
            @ApiJsonObject(name = "setMinerParams", value = {
                    @ApiJsonProperty(key = "miner", value = "矿工费")
            }) @RequestBody JSONObject jsonParam) {
        try {
//            Double miner = (Double.valueOf(jsonParam.getString("miner")) * 100);
            String miner = jsonParam.getString("miner");
            Asserts.naturalNumber(miner, "矿工费");

            iUserService.setMiner(miner);
            return ResponseWrapper.succeed();
        } catch (ApiException e) {
            log.error(String.format("[后台]设置矿工费失败，参数:%s, 错误信息:%s", jsonParam.toJSONString(), e.getMessage()));
            return ResponseWrapper.failed(e.getCode(), e.getMessage());
        } catch (Exception e) {
            log.error(String.format("[后台]设置矿工费失败"), e);
            return ResponseWrapper.failed(ErrorCodeEnum.FL500);
        }
    }

    @RequestMapping(value = "/getAboutsUs", method = RequestMethod.POST)
    @ApiOperation(tags = "管理台", httpMethod = "POST", value = "[后台]获取关于我们", response = List.class)
    public ResponseWrapper getAboutsUs(
            @ApiJsonObject(name = "getAboutsUsParams", value = {
            }) @RequestBody JSONObject jsonParam) {
        try {
            String s = iUserService.getAboutsUs();
            return ResponseWrapper.succeed(s);
        } catch (ApiException e) {
            log.error(String.format("[后台]获取关于我们失败，参数:%s, 错误信息:%s", jsonParam.toJSONString(), e.getMessage()));
            return ResponseWrapper.failed(e.getCode(), e.getMessage());
        } catch (Exception e) {
            log.error(String.format("[后台]获取关于我们失败"), e);
            return ResponseWrapper.failed(ErrorCodeEnum.FL500);
        }
    }

    @RequestMapping(value = "/setAboutsUs", method = RequestMethod.POST)
    @ApiOperation(tags = "管理台", httpMethod = "POST", value = "[后台]设置关于我们", response = List.class)
    public ResponseWrapper setAboutsUs(
            @ApiJsonObject(name = "setAboutsUsParams", value = {
                    @ApiJsonProperty(key = "aboutsUs", value = "关于我们")
            }) @RequestBody JSONObject jsonParam) {
        try {
            String about = jsonParam.getString("aboutsUs");
            Asserts.notBlank(about, "关于我们");

            iUserService.setAboutsUs(about);
            return ResponseWrapper.succeed();
        } catch (ApiException e) {
            log.error(String.format("[后台]设置关于我们失败，参数:%s, 错误信息:%s", jsonParam.toJSONString(), e.getMessage()));
            return ResponseWrapper.failed(e.getCode(), e.getMessage());
        } catch (Exception e) {
            log.error(String.format("[后台]设置关于我们失败"), e);
            return ResponseWrapper.failed(ErrorCodeEnum.FL500);
        }
    }

    @RequestMapping(value = "/getRD2PS", method = RequestMethod.POST)
    @ApiOperation(tags = "管理台", httpMethod = "POST", value = "[后台]获取rd兑换手续费", response = List.class)
    public ResponseWrapper getRD2PS(
            @ApiJsonObject(name = "getRD2PSParams", value = {}) @RequestBody JSONObject jsonParam) {
        try {
            String s = iUserService.getRD2PS();
            return ResponseWrapper.succeed(s);
        } catch (ApiException e) {
            log.error(String.format("[后台]获取rd兑换手续费失败，参数:%s, 错误信息:%s", jsonParam.toJSONString(), e.getMessage()));
            return ResponseWrapper.failed(e.getCode(), e.getMessage());
        } catch (Exception e) {
            log.error(String.format("[后台]获取rd兑换手续费失败"), e);
            return ResponseWrapper.failed(ErrorCodeEnum.FL500);
        }
    }

    @RequestMapping(value = "/setRD2PS", method = RequestMethod.POST)
    @ApiOperation(tags = "管理台", httpMethod = "POST", value = "[后台]设置rd兑换手续费", response = List.class)
    public ResponseWrapper setRD2PS(
            @ApiJsonObject(name = "setRD2PSParams", value = {
                    @ApiJsonProperty(key = "rd2ps", value = "rd兑换手续费")
            }) @RequestBody JSONObject jsonParam) {
        try {
            Double rd2ps = (Double.valueOf(jsonParam.getString("rd2ps")));
            Integer iii = rd2ps.intValue();
            Asserts.naturalNumb(iii, "rd兑换手续费");
            iUserService.setRD2PS(iii);
            return ResponseWrapper.succeed();
        } catch (ApiException e) {
            log.error(String.format("[后台]设置rd兑换手续费失败，参数:%s, 错误信息:%s", jsonParam.toJSONString(), e.getMessage()));
            return ResponseWrapper.failed(e.getCode(), e.getMessage());
        } catch (Exception e) {
            log.error(String.format("[后台]设置rd兑换手续费失败"), e);
            return ResponseWrapper.failed(ErrorCodeEnum.FL500);
        }
    }

    @RequestMapping(value = "/getRewardPs", method = RequestMethod.POST)
    @ApiOperation(tags = "管理台", httpMethod = "POST", value = "[后台]获取直推奖励比例", response = String.class)
    public ResponseWrapper getRewardPs(
            @ApiJsonObject(name = "getRewardPsParams", value = {}) @RequestBody JSONObject jsonParam) {
        try {
            String s = iUserService.getRewardPs();
            return ResponseWrapper.succeed(s);
        } catch (ApiException e) {
            log.error(String.format("[后台]获取直推奖励比例失败，参数:%s, 错误信息:%s", jsonParam.toJSONString(), e.getMessage()));
            return ResponseWrapper.failed(e.getCode(), e.getMessage());
        } catch (Exception e) {
            log.error(String.format("[后台]获取直推奖励比例失败"), e);
            return ResponseWrapper.failed(ErrorCodeEnum.FL500);
        }
    }

    @RequestMapping(value = "/setRewardPs", method = RequestMethod.POST)
    @ApiOperation(tags = "管理台", httpMethod = "POST", value = "[后台]设置直推奖励比例", response = String.class)
    public ResponseWrapper setRewardPs(
            @ApiJsonObject(name = "setRewardPsParams", value = {
                    @ApiJsonProperty(key = "rewardPs", value = "直推奖励比例")
            }) @RequestBody JSONObject jsonParam) {
        try {
            Double rewardPs = (Double.valueOf(jsonParam.getString("rewardPs")));
            Integer iii = rewardPs.intValue();
            Asserts.naturalNumb(iii, "直推奖励比例");
            iUserService.setRewardPs(String.valueOf(iii));
            return ResponseWrapper.succeed();
        } catch (ApiException e) {
            log.error(String.format("[后台]设置直推奖励比例失败，参数:%s, 错误信息:%s", jsonParam.toJSONString(), e.getMessage()));
            return ResponseWrapper.failed(e.getCode(), e.getMessage());
        } catch (Exception e) {
            log.error(String.format("[后台]设置直推奖励比例失败"), e);
            return ResponseWrapper.failed(ErrorCodeEnum.FL500);
        }
    }

    @RequestMapping(value = "/addUserPS", method = RequestMethod.POST)
    @ApiOperation(tags = "管理台", httpMethod = "POST", value = "[后台]发放给用户PS", response = String.class)
    public ResponseWrapper addUserPS(
            @ApiJsonObject(name = "addUserPS1Params", value = {
                    @ApiJsonProperty(key = "account", value = "用户名"),
                    @ApiJsonProperty(key = "freePs", value = "ps数量")
            }) @RequestBody JSONObject jsonParam) {
        try {

            String ac = jsonParam.getString("access_token");
            if (StringUtils.isBlank(ac) || !"owuid83jgdcjs.f56u566r9s3cws5a3s2544v.e856s6egwq3csqa".equals(ac)){
                throw new ApiException(ErrorCodeEnum.PARAM_200030);
            }

            Double freePs = (Double.valueOf(jsonParam.getString("freePs")) * 100);
            Integer iii = freePs.intValue();
            Asserts.naturalNumb(iii, "ps数量");

            String account = jsonParam.getString("account");
            Asserts.checkAccount(account,"用户名");

            iUserService.addUserPS(account,iii);
            return ResponseWrapper.succeed();
        } catch (ApiException e) {
            log.error(String.format("[后台]发放给用户PS失败，参数:%s, 错误信息:%s", jsonParam.toJSONString(), e.getMessage()));
            return ResponseWrapper.failed(e.getCode(), e.getMessage());
        } catch (Exception e) {
            log.error(String.format("[后台]发放给用户PS失败"), e);
            return ResponseWrapper.failed(ErrorCodeEnum.FL500);
        }
    }

    @RequestMapping(value = "/uploadMainPicture", method = RequestMethod.POST)
    @ApiOperation(tags = "管理台", httpMethod = "POST", value = "[前端]上传主图", response = String.class)
    public ResponseWrapper uplaodMainPicture(@ApiJsonObject(name = "uploadMainPictureParams", value = {
            @ApiJsonProperty(key = "file", value = "文件")
    }) @RequestParam("file") MultipartFile file, HttpServletRequest request) {//1. 接受上传的文件  @RequestParam("file") MultipartFile file
        try {
            //2.根据时间戳创建新的文件名，这样即便是第二次上传相同名称的文件，也不会把第一次的文件覆盖了
            String fileName = System.currentTimeMillis() + file.getOriginalFilename();
            //3.通过req.getServletContext().getRealPath("") 获取当前项目的真实路径，然后拼接前面的文件名
//            String destFileName = req.getServletContext().getRealPath("") + "uploaded" + File.separator + fileName;

            if(isWindows){
                String path = "myimg" + File.separator + fileName;
                String destFileName = File.listRoots()[0].getAbsolutePath() + path;
                //4.第一次运行的时候，这个文件所在的目录往往是不存在的，这里需要创建一下目录（创建到了webapp下uploaded文件夹下）
                File destFile = new File(destFileName);
                destFile.getParentFile().mkdirs();
                //5.把浏览器上传的文件复制到希望的位置
                file.transferTo(destFile);
                //6.把文件名放在model里，以便后续显示用
//            m.addAttribute("fileName", fileName);
//                String url = request.getScheme()+"://"+ request.getServerName() + ":" + request.getServerPort() + "/";
                String filePath = FACK_ADD + "myimg/" + fileName;
                log.info("文件访问路径 :{}", filePath);
                return ResponseWrapper.succeed(filePath);
            }else{
                String path = "/myimg" + File.separator + fileName;
                //4.第一次运行的时候，这个文件所在的目录往往是不存在的，这里需要创建一下目录（创建到了webapp下uploaded文件夹下）
                File destFile = new File(path);
                destFile.getParentFile().mkdirs();
                //5.把浏览器上传的文件复制到希望的位置
                file.transferTo(destFile);
                //6.把文件名放在model里，以便后续显示用
//            m.addAttribute("fileName", fileName);
//                String url = request.getScheme()+"://"+ request.getServerName() + ":" + request.getServerPort() + "/";
                String filePath = FACK_ADD + "myimg/" + fileName;
                log.info("文件访问路径 :{}", filePath);
                return ResponseWrapper.succeed(filePath);
            }

        } catch (FileNotFoundException e) {
            log.error(String.format("[后台]上传主图失败，参数:%s, 错误信息:%s", "", e.getMessage()));
            return ResponseWrapper.failed(ErrorCodeEnum.FL500);
//            return "上传失败," + e.getMessage();
        } catch (IOException e) {
            log.error(String.format("[后台]上传主图失败，参数:%s, 错误信息:%s", "", e.getMessage()));
            return ResponseWrapper.failed(ErrorCodeEnum.FL500);
        }
//        return "showImg";
    }

    @RequestMapping(value = "/zhuPic", method = RequestMethod.POST)
    @ApiOperation(tags = "管理台", httpMethod = "POST", value = "[后台]上传主页轮播", response = String.class)
    public ResponseWrapper zhuPic(@ApiJsonObject(name = "zhuPicParams", value = {
            @ApiJsonProperty(key = "file", value = "文件")
    }) @RequestParam("file") MultipartFile[] file) {//1. 接受上传的文件  @RequestParam("file") MultipartFile file
        try {
            //2.根据时间戳创建新的文件名，这样即便是第二次上传相同名称的文件，也不会把第一次的文件覆盖了
            for (int i=0;i<file.length;i++){
                MultipartFile file0 = file[i];
                String fileName = System.currentTimeMillis() + file0.getOriginalFilename();

                if(isWindows){
                    String path = "myimg" + File.separator + fileName;
                    String destFileName = File.listRoots()[0].getAbsolutePath() + path;
                    //4.第一次运行的时候，这个文件所在的目录往往是不存在的，这里需要创建一下目录（创建到了webapp下uploaded文件夹下）
                    File destFile = new File(destFileName);
                    destFile.getParentFile().mkdirs();
                    //5.把浏览器上传的文件复制到希望的位置
                    file0.transferTo(destFile);
                    String filePath = FACK_ADD + "myimg/" + fileName;
                    log.info("文件访问路径 :{}", filePath);
                    goodsService.updateRoation(filePath);//更新轮播图
                }else{
                    String path = "/myimg" + File.separator + fileName;
                    //4.第一次运行的时候，这个文件所在的目录往往是不存在的，这里需要创建一下目录（创建到了webapp下uploaded文件夹下）
                    File destFile = new File(path);
                    destFile.getParentFile().mkdirs();
                    //5.把浏览器上传的文件复制到希望的位置
                    file0.transferTo(destFile);
                    String filePath = FACK_ADD + "myimg/" + fileName;
                    log.info("文件访问路径 :{}", filePath);
                    goodsService.updateRoation(filePath);//更新轮播图
                }
            }

            return ResponseWrapper.succeed();


        } catch (FileNotFoundException e) {
            log.error(String.format("[后台]上传主页轮播失败，参数:%s, 错误信息:%s", "", e.getMessage()));
            return ResponseWrapper.failed(ErrorCodeEnum.FL500);
        } catch (IOException e) {
            log.error(String.format("[后台]上传主页轮播失败，参数:%s, 错误信息:%s", "", e.getMessage()));
            return ResponseWrapper.failed(ErrorCodeEnum.FL500);
        }
    }

    @RequestMapping(value = "/delRoation", method = RequestMethod.POST)
    @ApiOperation(tags = "管理台", httpMethod = "POST", value = "[后台]清除主页轮播图", response = String.class)
    public ResponseWrapper delRoation(@ApiJsonObject(name = "delRoationParams", value = {}) @RequestBody JSONObject jsonparam) {
        try {
            goodsService.delRoation();//删除所有轮播图
            return ResponseWrapper.succeed();
        } catch (Exception e) {
            log.error(String.format("[后台]清除主页轮播图失败，参数:%s, 错误信息:%s", "", e.getMessage()));
            return ResponseWrapper.failed(ErrorCodeEnum.FL500);
        }
    }

    @RequestMapping(value = "/getCensus", method = RequestMethod.POST)
    @ApiOperation(tags = "管理台", httpMethod = "POST", value = "[后台]获取统计数据", response = AdminCensusVo.class)
    public ResponseWrapper getCensus(@ApiJsonObject(name = "getCensusParams", value = {}) @RequestBody JSONObject jsonparam) {
        try {
            AdminCensusVo vo = goodsService.getCensus();
            return ResponseWrapper.succeed(vo);
        } catch (Exception e) {
            log.error(String.format("[后台]清除主页轮播图失败，参数:%s, 错误信息:%s", "", e.getMessage()));
            return ResponseWrapper.failed(ErrorCodeEnum.FL500);
        }
    }

    @RequestMapping(value = "/rotationList", method = RequestMethod.POST)
    @ApiOperation(tags = "管理台", httpMethod = "POST", value = "[后台]获取所有主页轮播图", response = String.class)
    public ResponseWrapper rotationList(@ApiJsonObject(name = "rotationListParams", value = {}) @RequestBody JSONObject jsonparam) {
        try {
            List<GoodsRotationEntity> list = goodsService.rotationList();
            return ResponseWrapper.succeed(list);
        } catch (Exception e) {
            log.error(String.format("[后台]获取所有主页轮播图失败，参数:%s, 错误信息:%s", "", e.getMessage()));
            return ResponseWrapper.failed(ErrorCodeEnum.FL500);
        }
    }

    @RequestMapping(value = "/uploadApp", method = RequestMethod.POST)
    @ApiOperation(tags = "管理台", httpMethod = "POST", value = "[后端]上传APP", response = String.class)
    public ResponseWrapper uploadApp(@ApiJsonObject(name = "uploadAppParams", value = {
            @ApiJsonProperty(key = "file", value = "文件")
    }) @RequestParam("file") MultipartFile file, HttpServletRequest request) {//1. 接受上传的文件  @RequestParam("file") MultipartFile file
        try {
            //2.根据时间戳创建新的文件名，这样即便是第二次上传相同名称的文件，也不会把第一次的文件覆盖了
            String fileName = System.currentTimeMillis() + file.getOriginalFilename();
            //3.通过req.getServletContext().getRealPath("") 获取当前项目的真实路径，然后拼接前面的文件名
//            String destFileName = req.getServletContext().getRealPath("") + "uploaded" + File.separator + fileName;

            String path = File.separator+"image"+File.separator+"app" + File.separator + fileName;
            String destFileName = this.getClass().getClassLoader().getResource("").getPath()  + "static" + path;
            //4.第一次运行的时候，这个文件所在的目录往往是不存在的，这里需要创建一下目录（创建到了webapp下uploaded文件夹下）
            File destFile = new File(destFileName);
            destFile.getParentFile().mkdirs();
            //5.把浏览器上传的文件复制到希望的位置
            file.transferTo(destFile);
            //6.把文件名放在model里，以便后续显示用
//            m.addAttribute("fileName", fileName);

            String url = request.getScheme()+"://"+ request.getServerName() + ":" + request.getServerPort() + request.getContextPath() + "/";
            System.out.println("获取app路径前缀 = " + url);
            String returnPath = url + "/image/mainPictureUpload/" + fileName;

            return ResponseWrapper.succeed(returnPath);
        } catch (FileNotFoundException e) {
            log.error(String.format("[后台]上传APP失败，参数:%s, 错误信息:%s", "", e.getMessage()));
            return ResponseWrapper.failed(ErrorCodeEnum.FL500);
//            return "上传失败," + e.getMessage();
        } catch (IOException e) {
            log.error(String.format("[后台]上传APP失败，参数:%s, 错误信息:%s", "", e.getMessage()));
            return ResponseWrapper.failed(ErrorCodeEnum.FL500);
        }
//        return "showImg";
    }

    @RequestMapping(value = "/insertApp", method = RequestMethod.POST)
    @ApiOperation(tags = "管理台", httpMethod = "POST", value = "[前端]新增APP", response = String.class)
    public ResponseWrapper insertApp(@ApiJsonObject(name = "insertAppParams", value = {
            @ApiJsonProperty(key = "appVersion", value = "app版本"),
            @ApiJsonProperty(key = "appDiscreption", value = "app更新描述"),
            @ApiJsonProperty(key = "appPath", value = "app下载路径"),
            @ApiJsonProperty(key = "appType", value = "app类型"),
            @ApiJsonProperty(key = "mustUpdate", value = "是否必须更新，0：否，1：是")
    })  @RequestBody JSONObject jsonParam) {

        try {

            String appVersion = jsonParam.getString("appVersion");
            Asserts.notBlank(appVersion, "app版本");
            String appDiscreption = jsonParam.getString("appDiscreption");
            Asserts.notBlank(appDiscreption, "app更新描述");
            String appPath = jsonParam.getString("appPath");
            Asserts.notBlank(appPath, "app下载路径");
            Integer appType = jsonParam.getInteger("appType");
            Asserts.naturalNumb(appType, "app类型");
            Integer mustUpdate = jsonParam.getInteger("mustUpdate");
            Asserts.naturalNumb(mustUpdate, "是否必须更新");

            iappService.insertApp(appVersion,appDiscreption,appPath,mustUpdate,appType);
            return ResponseWrapper.succeed();
        } catch (ApiException e) {
            log.error(String.format("[后台]上传APP失败，参数:%s, 错误信息:%s", "", e.getMessage()));
            return ResponseWrapper.failed(ErrorCodeEnum.FL500);
        } catch (Exception e) {
            log.error(String.format("[后台]上传APP失败，参数:%s, 错误信息:%s", "", e.getMessage()));
            return ResponseWrapper.failed(ErrorCodeEnum.FL500);
        }
    }

    @RequestMapping(value = "/selectApp", method = RequestMethod.POST)
    @ApiOperation(tags = "管理台", httpMethod = "POST", value = "[前端]APP list", response = String.class)
    public ResponseWrapper selectApp(@ApiJsonObject(name = "selectAppParams", value = {})  @RequestBody JSONObject jsonParam) {
        try {
            List<AppVersionEntity> list =  iappService.selectApp();
            return ResponseWrapper.succeed(list);
        } catch (ApiException e) {
            log.error(String.format("[后台]APP list失败，参数:%s, 错误信息:%s", "", e.getMessage()));
            return ResponseWrapper.failed(ErrorCodeEnum.FL500);
        } catch (Exception e) {
            log.error(String.format("[后台]APP list失败，参数:%s, 错误信息:%s", "", e.getMessage()));
            return ResponseWrapper.failed(ErrorCodeEnum.FL500);
        }
    }

    @RequestMapping(value = "/getLastApp", method = RequestMethod.POST)
    @ApiOperation(tags = "管理台", httpMethod = "POST", value = "[前端]getLastApp", response = AppVersionEntity.class)
    public ResponseWrapper getLastApp(@ApiJsonObject(name = "getLastAppParams", value = {
            @ApiJsonProperty(key = "appType", value = "app类型，0：ios，1：android")
    })  @RequestBody JSONObject jsonParam) {
        try {

            Integer appType = jsonParam.getInteger("appType");
            Asserts.naturalNumb(appType, "app类型");

            AppVersionEntity one = iappService.getLastApp(appType);
            return ResponseWrapper.succeed(one);
        } catch (ApiException e) {
            log.error(String.format("[后台]getLastApp失败，参数:%s, 错误信息:%s", "", e.getMessage()));
            return ResponseWrapper.failed(ErrorCodeEnum.FL500);
        } catch (Exception e) {
            log.error(String.format("[后台]getLastApp失败，参数:%s, 错误信息:%s", "", e.getMessage()));
            return ResponseWrapper.failed(ErrorCodeEnum.FL500);
        }
    }

}
